package com.qf.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.AntiFraud;
import com.qf.service.AntiFraudService;
import com.qf.util.AliyunOSSUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.qf.util.R;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
public class AntiFraudController {

    private Logger logger = LogManager.getLogger(AntiFraudController.class);
    @Autowired
    private AntiFraudService service;
    //分页迷糊查询全部
    @PostMapping ("/antiFraud")
    public R antiFraud(@RequestBody AntiFraud antiFraud){
        logger.debug("AntiFraud ==> {}", antiFraud);
        PageHelper.startPage(antiFraud.getPageNum(),antiFraud.getPageSize());
        List<AntiFraud> list=  service.antiFraud(antiFraud);
        PageInfo<AntiFraud> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    /**
     * 删除信息
     */
    @GetMapping("/delete/antiFraud")
    public R delete(Integer id){
        service.delete(id);
        return R.ok();
    }


    // 上传文件
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        String url = AliyunOSSUtil.upLoad(file);
        return R.ok(url);
    }

    /**
     * 添加信息
     */
    @PostMapping("/add/antiFraud")
    public R add(@RequestBody AntiFraud antiFraud){
        service.add(antiFraud);
        return R.ok();
    }

    /**
     * 修改信息
     */
    @PostMapping("/update/antiFraud")
    public R update(@RequestBody AntiFraud antiFraud){
        service.update(antiFraud);
        return R.ok();
    }
}
